package ar.com.ford.it.fullEconomics.view.form;

import java.util.Collection;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.util.MessageResources;
import org.apache.struts.validator.ValidatorForm;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesp01Part;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesp02Commodity;

public class CommodityMembersForm extends ValidatorForm {
    private String section;
    private String commodityCode;
    private String commodityName;
    private String commodityCodeFind;
    private String prefix;
    private String base;
    private String suffix;
    private String partClass;
    private String lowCom;
    private Collection<Teesp01Part> commodityParts;
    private Collection<Teesp01Part> parts;
    private String[] selectedParts;
    private Teesp02Commodity commodity;
    private String createDate;
    private String modifDate;

    /**
     * Resetea el formulario
     * 
     */
    public void resetForm() {
        this.section = "";
        this.prefix = null;
        this.base = null;
        this.suffix = null;
        this.partClass = null;
        this.lowCom = null;
        this.commodityCodeFind = null;
        this.partClass = "F";
    }

    /**
     * Genera las validaciones necesarias.
     */
    public ActionErrors validate(ActionMapping mapping,
                                 HttpServletRequest request) {

        ActionErrors ae = new ActionErrors();
        MessageResources resources = (MessageResources) request
                .getAttribute(org.apache.struts.Globals.MESSAGES_KEY);
        if ("quickSearch".equalsIgnoreCase(this.getSection())) {
            try{
                if(Integer.valueOf(this.getCommodityCodeFind()) < 0)
                   ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
                   "commodityMembers.error.invalidCode"));
            }catch(Exception e){
                ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
                        "commodityMembers.error.invalidCode"));
            }
        }

        return ae;
    }

    public String getBase() {
        return base;
    }

    public void setBase(String base) {
        this.base = base.toUpperCase();
    }

    public String getCommodityCode() {
        return commodityCode;
    }

    public void setCommodityCode(String commodityCode) {
        this.commodityCode = commodityCode;
    }

    public String getCommodityName() {
        return commodityName;
    }

    public void setCommodityName(String commodityName) {
        this.commodityName = commodityName.toUpperCase();
    }

    public String getLowCom() {
        return lowCom;
    }

    public void setLowCom(String lowCom) {
        this.lowCom = lowCom.toUpperCase();
    }

    public String getPartClass() {
        return partClass;
    }

    public void setPartClass(String partClass) {
        this.partClass = partClass;
    }

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix.toUpperCase();
    }

    public String getSection() {
        return section;
    }

    public void setSection(String section) {
        this.section = section;
    }

    public String getSuffix() {
        return suffix;
    }

    public void setSuffix(String suffix) {
        this.suffix = suffix.toUpperCase();
    }

    public Teesp02Commodity getCommodity() {
        return commodity;
    }

    public void setCommodity(Teesp02Commodity commodity) {
        this.commodity = commodity;
    }

    public String getCommodityCodeFind() {
        return commodityCodeFind;
    }

    public void setCommodityCodeFind(String commodityCodeFind) {
        this.commodityCodeFind = commodityCodeFind;
    }

    public Collection<Teesp01Part> getCommodityParts() {
        return commodityParts;
    }

    public void setCommodityParts(Collection<Teesp01Part> commodityParts) {
        this.commodityParts = commodityParts;
    }

    public Collection<Teesp01Part> getParts() {
        return parts;
    }

    public void setParts(Collection<Teesp01Part> parts) {
        this.parts = parts;
    }

    public String[] getSelectedParts() {
        return selectedParts;
    }

    public void setSelectedParts(String[] selectedParts) {
        this.selectedParts = selectedParts;
    }

    public String getCreateDate() {
        return createDate;
    }

    public void setCreateDate(String createDate) {
        this.createDate = createDate;
    }

    public String getModifDate() {
        return modifDate;
    }

    public void setModifDate(String modifDate) {
        this.modifDate = modifDate;
    }
    
    public void reset(ActionMapping mapping, HttpServletRequest request){
        this.selectedParts = new String[0];
    }
}
